package com.baosight.sczx.zm.cg.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ef.chart.ChartUtils;
import com.baosight.iplat4j.ef.chart.EfChart;
import com.baosight.iplat4j.ef.chart.chartElement.CEApply;
import com.baosight.iplat4j.ef.chart.chartElement.CEDataSeries;
import com.baosight.iplat4j.ef.chart.chartElement.styleImpl.SAnimation;
import com.baosight.iplat4j.ef.chart.chartElement.styleImpl.SFont;
import com.baosight.iplat4j.ef.chart.service.ServiceChartBase;
import com.baosight.sczx.zm.ch.domain.ZMCHProduceReport;
import com.baosight.sczx.zm.cp.domain.ZMCPProfessionalPlan;

public class ServiceZMCGG0 extends ServiceChartBase{
	
	/**
	 * 初始化
	 */
	@SuppressWarnings("rawtypes")
	List xunActual;
	@SuppressWarnings("rawtypes")
	List yuePlan;
	
	public String[] genInitChartInfo(EiInfo info){
		StringBuffer sb = new StringBuffer();
		sb.append(ChartUtils.chartAttr2Str("bgcolor",info.getString("bgcolor")));
		sb.append(ChartUtils.chartAttr2Str("canvasBgColor",info.getString("canvasBgColor")));
		sb.append(ChartUtils.chartAttr2Str("showValues",info.getString("showValues")));
		
	    return new String[]{"月计划实际对比","月份","销售量",null,null,null,null,sb.toString()};
	}
	
	/**
	 * 查询方法
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCGG0</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-9-12 上午14:47:20 卢健
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) 
	{
		String fdNf = inInfo.getString("year");
		String fdYf = inInfo.getString("month");
		String fdMiningId = UserSession.getInSessionProperty("miningCode").toString();
		Map<String, String>	params = new HashMap<String, String>();
        params.put("fdYear", fdNf);
        params.put("fdMonth", fdYf);
        params.put("fdMiningId", fdMiningId);
		xunActual  = dao.query("ZMCHProduceReport.queryMine",params);//旬实际
		
		
		params.put("fdPlanYear", fdNf);
		params.put("fdPlanMonth", fdYf);
		yuePlan = dao.query("ZMCPProfessionalPlan.queryMine",params);//月计划
      return inInfo;
	}
	
	/**
	 * category
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List genChartCatLabels(EiInfo info){
		List list = new ArrayList();

				list.add("上旬");
				list.add("中旬");
				list.add("下旬");
		return list;
	}
	
	public void setChartStyle(EiInfo info, EfChart chart){
		if(!"1".equals(info.getString("dataType"))){
			//样式--定义
			SAnimation animation = new SAnimation("Anim1");
			animation.setParam("_yScale");
			animation.setStart("0");
			animation.setDuration("1");
			chart.addStyleDefinition(animation);
			
			SAnimation animation2 = new SAnimation("Anim2");
			animation2.setParam("_alpha");
			animation2.setStart("0");
			animation2.setDuration("5");
			animation2.setEasing("strong");
			chart.addStyleDefinition(animation2);
			
			//设置ShowValues背景及显示字体颜色
			SFont font = new SFont("font1");
			font.setBorderColor("1D8BD1");
			font.setBgColor("1D8BD1");
			font.setColor("FFFFFF");
			chart.addStyleDefinition(font);
			//样式--应用
			chart.addStyleApply(new CEApply(animation,"VLINES"));
			chart.addStyleApply(animation2,"TRENDLINES");
			chart.addStyleApply(font,"DATAVALUES");
		}
	}
	
	protected boolean isMData(EiInfo info){
		if(!"1".equals(info.getString("dataType"))){
			return true;
		}
		return false;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	protected List genSeriesNames(EiInfo info){
		List list = new ArrayList();
		list.add("实际");
		list.add("计划");
		return list;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	protected List genMChartDataValues(EiInfo info){
		BigDecimal early = new BigDecimal("0") ;
		BigDecimal middle = new BigDecimal("0");
		BigDecimal late = new BigDecimal("0");
		BigDecimal monthPlan = new BigDecimal("0");
		BigDecimal fdCheckYm;
		BigDecimal fdYmSum;
		String fdDateType;
		if(xunActual!= null && xunActual.size()>0){
			for(int i=0;i<xunActual.size();i++){
				ZMCHProduceReport bean = (ZMCHProduceReport)xunActual.get(i);
				fdDateType = bean.getFdDateType();
				fdCheckYm = bean.getFdCheckYm();
				if(fdDateType !=null && ("4c9abb8bc0a801c30198f5833986f3c3").equals(fdDateType)){
					early = fdCheckYm;
				}
				if(fdDateType !=null && ("4c9abb93c0a801c30198f583f36ce365").equals(fdDateType)){
					middle = fdCheckYm;
				}
				if(fdDateType !=null && ("4c9abb9bc0a801c30198f58334b1a863").equals(fdDateType)){
					late = fdCheckYm;
				}
			}
		}
		
		if(yuePlan!= null && yuePlan.size()>0){
		ZMCPProfessionalPlan bean1 = (ZMCPProfessionalPlan)yuePlan.get(0);
		fdYmSum = bean1.getFdYmSum();
		monthPlan = fdYmSum.divide(new BigDecimal("3"),0,BigDecimal.ROUND_HALF_UP);
		}
		List list = new ArrayList();
	
		
		List list1 = new ArrayList();//实际量
		list1.add(early.toString());
		list1.add(middle.toString());
		list1.add(late.toString());
		list.add(list1);
		
		List list2 = new ArrayList();//计划量
		list2.add(monthPlan.toString());
		list2.add(monthPlan.toString());
		list2.add(monthPlan.toString());
		list.add(list2);
		
		return list;
	}

	/**
	 * 设置对应柱状显示颜色
	 * @return
	 */	
	@SuppressWarnings({ "rawtypes", "unused" })
	protected List genMChartDatasetList(EiInfo info){
		String chartType = info.getString("chartType");
		List list = super.genMChartDatasetList(info);
		
		CEDataSeries datasetSeries1 = (CEDataSeries)list.get(0);
		datasetSeries1.setColor("FF7FFF");
		datasetSeries1.setShowValues("1");
		
		CEDataSeries datasetSeries2 = (CEDataSeries)list.get(1);
		datasetSeries2.setColor("FF0000");
		datasetSeries2.setShowValues("1");
		
		return list;
	}
}
